package com.xtq.container;

import java.util.HashMap;
import java.util.Map;

public class IoCContainer {
    private Map<Class<?>, Object> beans = new HashMap<>();
    
    // 注册Bean：根据接口和实现类注册
    public <T> void registerBean(Class<T> interfaceClass, Class<? extends T> clazz) {
        try {
            T instance = clazz.getDeclaredConstructor().newInstance();
            beans.put(interfaceClass, instance);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    // 获取Bean实例
    public <T> T getBean(Class<T> interfaceClass) {
        return (T) beans.get(interfaceClass);
    }
}
